#delimit;
clear all;
set more off;

capture log using "11_DAF_Grantee_Regressions.log", replace;
/*******************************************************************************************/;
** INPUT: This uses the DAF grantee data from Guidestar that is combined with grantee financial;
**        and governance info from NBER/AWS as well as inequality data from Chetty et al.;
** OUTPUT: Regression tables relating DAF characteristics to where grants get allocated;
** LAST MODIFIED: JAG, 9/4/2021;
** RUN TIME: <5 minutes using Stata 15 on computer with 2 x 2.60GHz processors and 64GB RAM;
/*******************************************************************************************/;

** Key questions want to understand: how, if at all, do DAFs help to level the charity playing field;
** We explore this by looking at if DAFs channel a greater percent of their donor dollars in a particular direction;
** E.g., do innovative DAFs channel more money to grantees in commuting zones with more inequality (Chetty et al);

use "DAF-Grants combined for regs at DAF-year level.dta", clear;
replace family=0 if family==.;
replace inv_rev_gr=0 if inv_rev_gr==.;
** Designate controls and fixed effects;
local controls="daf_size daf_age contr_gr inv_rev_gr family";
local fixed_effects="year naics daf_state";
local std_errors="vce(cluster ein)";

label var style_trad "Traditional";
label var style_innov "Innovative";
label var style_disrupt "Disruptive innovation";
label var feature_tool "Access to FinTech tools";
label var feature_relation "Chances to build relationships";
label var is_inclusive "Inclusive";
label var focus_dei "Diversity, equity, and inclusion"; 

** Inequality table (value-weighted);
local all_comb="style_trad style_innov style_disrupt feature_tool feature_relation is_inclusive focus_dei";
local dep_var="vw_dga_ineq";
label var `dep_var' "High inequality";	
sum `dep_var', d;
sum `dep_var' if style_trad!=. & style_innov!=. & style_disrupt!=. & comm_daf!=. & feature_tool!=. & feature_relation!=. & is_inclusive!=. & focus_dei!=. & daf_size!=. & daf_age!=. & contr_gr!=. & inv_rev_gr!=. & family!=.;

	eststo ols_ineq1vw: reghdfe `dep_var' style_trad `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels replace starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);		
	eststo ols_ineq2vw: reghdfe `dep_var' style_innov `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq3vw: reghdfe `dep_var' style_disrupt `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq4vw: reghdfe `dep_var' feature_tool `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq5vw: reghdfe `dep_var' feature_relation `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq6vw: reghdfe `dep_var' is_inclusive `controls', absorb(`fixed_effects') `std_error';	
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq7vw: reghdfe `dep_var' focus_dei `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
	eststo ols_ineq8vw: reghdfe `dep_var' `all_comb' `controls', absorb(`fixed_effects') `std_error';	
	outreg using "Regs/ols_ineq_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	

** EXPORT OLS inequality table with value-weighting;
esttab ols_ineq* using "tex/ols_ineq_vw_ntl.tex", replace b(3) se(3) ar2 drop(daf_size inv_rev_gr daf_age contr_gr family _cons) label star(* 0.10 ** 0.05 *** 0.001) noconstant frag;
est clear;

** ROBUSTNESS CHECK OF INEQUALITY TABLE THAT GOES IN APPENDIX;
local all_comb="style_trad style_innov style_disrupt feature_tool feature_relation is_inclusive focus_dei";
local dep_var="vw_dga_ineq2";
sum `dep_var', d;
sum `dep_var' if style_trad!=. & style_innov!=. & style_disrupt!=. & comm_daf!=. & feature_tool!=. & feature_relation!=. & is_inclusive!=. & focus_dei!=. & daf_size!=. & daf_age!=. & contr_gr!=. & inv_rev_gr!=. & family!=.;

label var `dep_var' "High inequality";	
	eststo ols_ineq1vw: reghdfe `dep_var' `all_comb' `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_robust", se varlabels replace starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	
local dep_var="high_ineq";
sum `dep_var', d;
sum `dep_var' if style_trad!=. & style_innov!=. & style_disrupt!=. & comm_daf!=. & feature_tool!=. & feature_relation!=. & is_inclusive!=. & focus_dei!=. & daf_size!=. & daf_age!=. & contr_gr!=. & inv_rev_gr!=. & family!=.;
label var `dep_var' "High inequality";			
	eststo ols_ineq2vw: reghdfe `dep_var' `all_comb' `controls', absorb(`fixed_effects') `std_error';
		outreg using "Regs/ols_ineq_robust", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age contr_gr inv_rev_gr family _cons);	

** EXPORT ols inequality table with value-weighting;
esttab ols_ineq* using "tex/ols_ineq_robust_appx.tex", replace b(3) se(3) ar2 drop(daf_size inv_rev_gr daf_age contr_gr family _cons) label star(* 0.10 ** 0.05 *** 0.001) noconstant frag;
est clear;		
	
** Label variables for financial instability and efficiency of charity;
local all_comb="style_trad style_innov style_disrupt feature_tool feature_relation is_inclusive focus_dei";
local dep_var="vw_dga_lag_gr_volat";
label var `dep_var' "High donation volatility";
local dep_var="vw_dga_lag_gr_adm_eff";
label var `dep_var' "High admin. eff.";
local controls="daf_size daf_age contr_gr inv_rev_gr family";
local dep_var="vw_dga_lag_gr_volat";
sum `dep_var', d;
sum `dep_var' if style_trad!=. & style_innov!=. & style_disrupt!=. & comm_daf!=. & feature_tool!=. & feature_relation!=. & is_inclusive!=. & focus_dei!=. & daf_size!=. & daf_age!=. & contr_gr!=. & inv_rev_gr!=. & family!=.;
label var `dep_var' "High donation volatility";
	eststo ols_otr1vw: reghdfe `dep_var' style_innov style_disrupt `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels replace starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);	
	eststo ols_otr2vw: reghdfe `dep_var' feature_tool feature_relation `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);
	eststo ols_otr3vw: reghdfe `dep_var' is_inclusive focus_dei `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);	
local dep_var="vw_dga_lag_gr_adm_eff";
sum `dep_var', d;
sum `dep_var' if style_trad!=. & style_innov!=. & style_disrupt!=. & comm_daf!=. & feature_tool!=. & feature_relation!=. & is_inclusive!=. & focus_dei!=. & daf_size!=. & daf_age!=. & contr_gr!=. & inv_rev_gr!=. & family!=.;
	eststo ols_otr4vw: reghdfe `dep_var' style_innov style_disrupt `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);	
	eststo ols_otr5vw: reghdfe `dep_var' feature_tool feature_relation `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);
	eststo ols_otr6vw: reghdfe `dep_var'  is_inclusive focus_dei `controls', absorb(`fixed_effects') `std_error';
	outreg using "Regs/ols_otrmatch_vw_ntl", se varlabels merge starlevels(10 5 1) drop(daf_size daf_age inv_rev_gr contr_gr family _cons);
** EXPORT ols financial instability and governance efficiency table with value-weighting;
esttab ols_otr* using "tex/ols_otr_vw_ntl.tex", replace b(3) se(3) ar2 drop(daf_size daf_age contr_gr inv_rev_gr family _cons) label star(* 0.10 ** 0.05 *** 0.001) noconstant;
est clear;		

	
log close;
